﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Simple.Services
{
    public class ParentChildTasksDto : ModelBase
    {
        public Guid Id { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string? Title { get; set; }

        /// <summary>
        /// 任务简介
        /// </summary>
        public string? TaskIntroduction { get; set; }

        /// <summary>
        /// 班级id
        /// </summary>
        public Guid ClassId { get; set; }

        /// <summary>
        /// 班级名称
        /// </summary>
        public string? ClassName { get; set; }

        /// <summary>
        /// 打卡天数
        /// </summary>
        public int ClockInDays { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 每日打卡截止时间
        /// </summary>
        public string? DailyClockInDeadline { get; set; }

        /// <summary>
        /// 任务状态
        /// </summary>
        public ParentChildTasksState StateEnum
        {
            get
            {
                var dateNow = DateTime.Now;
                if (StartDate > dateNow) return ParentChildTasksState.NotStarted;
                else if (EndDate < dateNow) return ParentChildTasksState.Ended;
                else return ParentChildTasksState.HaveInHand;
            }
        }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedTime { get; set; }

        /// <summary>
        /// 创建用户Id
        /// </summary>
        public Guid? CreatedUserId { get; set; }

        /// <summary>
        /// 创建用户
        /// </summary>
        public string? CreatedUser { get; set; }

        /// <summary>
        /// 状态Str
        /// </summary>
        public string? StateStr
        {
            get
            {
                return EnumHelper.GetDescriptionContent(StateEnum);
            }
        }

        /// <summary>
        /// 参与人数
        /// </summary>
        public int? Count { get; set; } = 0;

        /// <summary>
        /// 内容图片
        /// </summary>
        public List<ParentChildTasksImage>? Images { get; set; }

        public override void ConfigureMapper(Profile profile)
        {
            profile.CreateMap<ParentChildTasks, ParentChildTasksDto>();

            profile.CreateMap<ParentChildTasksDto, ParentChildTasks>();

        }
    }

    public class ParentChildTasksInfo : ModelBase
    {

        public Guid Id { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string? Title { get; set; }

        /// <summary>
        /// 班级id
        /// </summary>
        public Guid? ClassId { get; set; }

        /// <summary>
        /// 班级名称
        /// </summary>
        public string? ClassName { get; set; }

        /// <summary>
        /// 打卡天数
        /// </summary>
        public int ClockInDays { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedTime { get; set; }

        /// <summary>
        /// 创建用户Id
        /// </summary>
        public Guid? CreatedUserId { get; set; }

        /// <summary>
        /// 创建用户
        /// </summary>
        public string? CreatedUser { get; set; }

        /// <summary>
        /// 任务简介
        /// </summary>
        public string? TaskIntroduction { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 剩余天数
        /// </summary>
        public int? DaysRemaining { get { return EndDate.Value.Date.Subtract(DateTime.Now.Date).Days + 1; } }

        /// <summary>
        /// 参与人数
        /// </summary>
        public int Count { get; set; } = 0;

        /// <summary>
        /// 每日打卡截止时间
        /// </summary>
        public string? DailyClockInDeadline { get; set; }

        /// <summary>
        /// 任务状态
        /// </summary>
        public ParentChildTasksState StateEnum
        {
            get
            {
                var dateNow = DateTime.Now;
                if (StartDate > dateNow) return ParentChildTasksState.NotStarted;
                else if (EndDate < dateNow) return ParentChildTasksState.Ended;
                else return ParentChildTasksState.HaveInHand;
            }
        }

        /// <summary>
        /// 状态Str
        /// </summary>
        public string? StateStr
        {
            get
            {
                return EnumHelper.GetDescriptionContent(StateEnum);
            }
        }

        /// <summary>
        /// 内容图片
        /// </summary>
        public List<ParentChildTasksImage>? Images { get; set; }


        public override void ConfigureMapper(Profile profile)
        {
            profile.CreateMap<ParentChildTasks, ParentChildTasksInfo>();

            profile.CreateMap<ParentChildTasksInfo, ParentChildTasks>();

        }
    }


    public class RecodeDto : ModelBase
    {

        public Guid Id { get; set; }
        /// <summary>
        /// 记录内容
        /// </summary>
        public string? Content { get; set; }

        /// <summary>
        /// 家属关系
        /// </summary>
        public int? Relationship { get; set; }

        /// <summary>
        /// 关联幼儿Id
        /// </summary>
        public Guid? RelationshipChildrenId { get; set; }

        /// <summary>
        /// 创建用户Id
        /// </summary>
        public Guid? CreatedUserId { get; set; }

        /// <summary>
        /// 创建人称呼
        /// </summary>
        public string? CreateUserName { get; set; }

        /// <summary>
        /// 家长头像
        /// </summary>
        public Guid? ParentImgId { get; set; }

        /// <summary>
        /// 打卡次数
        /// </summary>
        public string? ClockInTimes { get; set; }

        /// <summary>
        /// 是第几次打卡
        /// </summary>
        public int HowManyTimes { get; set; }

        public List<ParentChildTasksRecordImage>? Images { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedTime { get; set; }

        public override void ConfigureMapper(Profile profile)
        {
            profile.CreateMap<ParentChildTasksRecord, RecodeDto>();

            profile.CreateMap<RecodeDto, ParentChildTasksRecord>();

        }
    }

    public class PreviewDto
    {
        /// <summary>
        /// 任务信息
        /// </summary>
        public ParentChildTasksInfo? parentChildTasksInfo { get; set; }

        /// <summary>
        /// 完成任务记录
        /// </summary>
        public List<RecodeDto>? RecodeList { get; set; }
    }


    public class Tasks
    {
        public Guid Id { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string? Title { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string? Content { get; set; }
    }

    public class TasksDetilDto
    {
        /// <summary>
        /// 任务信息
        /// </summary>
        public ParentChildTasksInfo Info { get; set; }

        /// <summary>
        /// 我的任务情况
        /// </summary>
        public Dictionary<int, bool> MyTasks { get; set; }

        /// <summary>
        /// 班级记录
        /// </summary>
        public List<RecodeDto>? RecodeList { get; set; }
    }

    public class CompleteStatisticsDto
    {
        /// <summary>
        /// 总数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 完成人数
        /// </summary>
        public int Completed { get; set; }

        /// <summary>
        /// 完成学生
        /// </summary>
        public List<StudentTasksInfo>? CompleteStudent { get; set; }

        /// <summary>
        /// 未完成学生
        /// </summary>
        public List<StudentTasksInfo>? UnfinishedStudents { get; set; }
    }

    public class StudentTasksInfo
    {
        /// <summary>
        /// 学生id
        /// </summary>
        public Guid StudentId { get; set; }

        /// <summary>
        /// 学生名字
        /// </summary>
        public string StudentName { get; set; }

        /// <summary>
        /// 学生头像
        /// </summary>
        public Guid? ImgId { get; set; }

        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime? CompletionTime { get; set; }

    }
}
